# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.db import models

class DocCategory(models.Model):
    title = models.CharField(max_length=150, verbose_name=u"Заголовок категории")
    access = models.ManyToManyField(User, blank=True, null=True, verbose_name=u"Кто может просматривать")

    def get_documents(self):
        return Document.objects.filter(category=self)

    def get_absolute_url(self):
        return reverse('docs_detail', args=[self.pk])

    class Meta:
        verbose_name=u'Категория'
        verbose_name_plural = u'Категории'

    def __unicode__(self):
        return u'%s' % self.title

class Document(models.Model):
    category = models.ForeignKey(DocCategory, verbose_name=u"Категория документа")
    title = models.CharField(max_length=150, verbose_name=u"Название документа")
    doc = models.FileField(upload_to='docs', verbose_name=u'Документ')
    enabled = models.BooleanField(default=True, verbose_name=u"Доступен ли документ?")

    class Meta:
        verbose_name=u'Документ'
        verbose_name_plural = u'Документы'

    def __unicode__(self):
        return u'%s' % self.title
